<template>
  <div class="app-container">
    <div class="search-container">
      <el-form v-show="showSearch" ref="queryParamsRef" :inline="true" :model="queryParams" label-width="100px">
        <el-form-item label="消耗品编码" prop="materialCode">
          <el-input
            v-model="queryParams.materialCode"
            clearable
            placeholder="请输入消耗品编码"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="消耗品名称" prop="materialName">
          <el-input
            v-model="queryParams.materialName"
            clearable
            placeholder="请输入消耗品名称"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        
        <el-form-item>
          <query-form-button @handleQuery="handleQuery" @resetQuery="resetQuery"/>
        </el-form-item>
      </el-form>
    </div>
    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button
          v-hasPerm="['material:materialPriceLog:export']"
          plain
          type="warning"
          @click="handleExport"
        >
          <template #icon>
            <i-ep-download/>
          </template>
          导出
        </el-button>
      </el-col> -->
    </el-row>

    <el-table v-adaptive :border="true" :data="materialPriceLogList" :header-cell-style="$headerCellStyle"
              :stripe="true" highlight-current-row > 
      <el-table-column :align="'center'" label="消耗品名称" prop="materialName"/>
      <el-table-column :align="'center'" label="消耗品编码" prop="materialCode"/> 
      <el-table-column :align="'center'" label="包装规格" prop="packageSpec"/>
      <el-table-column :align="'center'" label="消耗品单位" prop="units">
        <template #default="scope">
          <dict-data-tag :options="dictDataMap['spec_unit']" :value="scope.row.units"/>
        </template>
      </el-table-column>
      <el-table-column :show-overflow-tooltip="true" :align="'center'" label="门诊费用分类" min-width="100px"
          prop="classOnRcpt">
          <template #default="scope">
              <dict-data-tag :options="dictDataMap['outp_rcpt_fee_dict']" :value="scope.row.classOnRcpt" />
          </template>
      </el-table-column>
      <el-table-column :show-overflow-tooltip="true" :align="'center'" label="住院费用分类" min-width="100px"
          prop="classOnInp">
          <template #default="scope">
              <dict-data-tag :options="dictDataMap['inp_rcpt_fee_dict']" :value="scope.row.classOnInp" />
          </template>
      </el-table-column>
      <el-table-column :show-overflow-tooltip="true" :align="'center'" label="核算项目分类" min-width="100px"
          prop="classOnReckoning">
          <template #default="scope">
              <dict-data-tag :options="dictDataMap['reck_item_class_dict']" :value="scope.row.classOnReckoning" />
          </template>
      </el-table-column>
      <el-table-column :show-overflow-tooltip="true" :align="'center'" label="会计科目" min-width="100px"
          prop="subjCode">
          <template #default="scope">
              <dict-data-tag :options="dictDataMap['tally_subject_dict']" :value="scope.row.subjCode" />
          </template>
      </el-table-column>
      <el-table-column :show-overflow-tooltip="true" :align="'center'" label="病案首页分类" min-width="180px"
          prop="classOnMr">
          <template #default="scope">
              <dict-data-tag :options="dictDataMap['mr_fee_class_dict']" :value="scope.row.classOnMr" />
          </template>
      </el-table-column>
      <el-table-column :align="'center'" label="网络价格" prop="networkPrice"/>
      <el-table-column :align="'center'" label="市场批发价" prop="tradePrice"/>
      <el-table-column :align="'center'" label="市场零售价" prop="retailPrice"/>
      <el-table-column :align="'center'" label="起用日期" prop="startDate" width="150">
      </el-table-column>
      <el-table-column :align="'center'" label="停止日期" prop="stopDate" width="150">
      </el-table-column>
      
      <el-table-column :align="'center'" label="最高限价" prop="priceMax"/>
      <el-table-column :align="'center'" label="操作类型" prop="operationType">
        <template #default="scope">
          <dict-data-tag :options="dictDataMap['price_operation_type']" :value="scope.row.operationType" />
        </template>
      </el-table-column>
      <el-table-column :align="'center'" label="是否最新价格记录" min-width="100px" prop="isNew">
        <template #default="scope">
          <dict-data-tag :options="dictDataMap['is_new']" :value="scope.row.isNew" />
      </template>
      </el-table-column>
      <el-table-column :align="'center'" label="比例" prop="ratio"/>  
      <el-table-column :align="'center'" :show-overflow-tooltip="true"  label="操作人名称"  prop="updateByName"/>
      <el-table-column :align="'center'" label="操作时间" prop="updateTime" width="130"/>
      <el-table-column :align="'center'" label="备注信息" prop="remarks"/> 

    </el-table>

    <pagination
      v-show="total>0"
      v-model:limit="queryParams.pageSize"
      v-model:page="queryParams.pageNum"
      :total="total"
      @pagination="getList"
    />

    
  </div>
</template>
<script lang="ts">
export default {
  name: "MaterialPriceLog"
}
</script>

<script lang="ts" setup>
import {
  selectPageMaterialPriceLog
} from "@/api/material/materialPriceLog";

import {useDictStoreHook} from "@/store/modules/dict";
import {useUserStoreHook} from "@/store/modules/user";

const dictStore = useDictStoreHook();
const useUserStore = useUserStoreHook();
let dictDataMap = ref(dictStore.isTypeGetData('spec_unit', 'tally_subject_dict', 'bill_item_class_dict', 'outp_rcpt_fee_dict', 'inp_rcpt_fee_dict','reck_item_class_dict', 'mr_fee_class_dict', 'is_medical_insurance', 'price_operation_type', 'is_new'))


const {proxy} = getCurrentInstance() as any;
const userInfo = <UserInfoBusi>useUserStore.user.userInfo
const queryParamsRef = ref()
const materialPriceLogList = ref([]);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);


const queryParams = ref({
  pageNum: 1,
  pageSize: 10,
  materialCode: "",
  materialName: "",
  orgId: userInfo.orgId,
})

if (userInfo.orgId) {
    queryParams.value.orgId = userInfo.orgId
    getList()
}


/** 查询消耗品价格日志material_price_log列表 */
function getList() {
  selectPageMaterialPriceLog(queryParams.value).then((response: any) => {
    materialPriceLogList.value = response.rows;
    console.log(materialPriceLogList.value)
    total.value = response.total;
  });
}


/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  queryParamsRef.value.resetFields()
  // proxy.resetForm("queryRef");
  handleQuery();
}

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.materialPriceLogId);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}


/** 导出按钮操作 */
function handleExport() {
  // proxy.download('material/materialPriceLog/export', {
  //   ...queryParams.value
  // }, `materialPriceLog_${new Date().getTime()}.xlsx`)
}

getList();
</script>
